import request from './apiConfig'
const base_url = '/users'
    /**
     * 分页查询用户列表
     * @param {*} query
     */
export function listUserApi(query) {
    return request({
        url: base_url,
        method: 'GET',
        params: query,
    })
}

/**
 * 根据id获取用户信息
 * @param {*} query 
 */
export function getUserByIdApi(id) {
    return request({
        url: `${base_url}/${id}`,
        method: 'GET',
    })
}

/**
 * 添加用户
 * @param {*} user
 */
export function insertUserApi(user) {
    return request({
        url: base_url,
        method: 'POST',
        data: user
    })
}

/**
 * 根据id删除单个用户
 * @param {*} id
 */
export function delOneUserApi(id) {
    return request({
        url: `${base_url}/${id}`,
        method: 'DELETE',
    })
}
/**
 * 批量删除用户
 * @param {*} id
 */
export function delListUserApi(ids) {
    return request({
        url: base_url,
        method: 'DELETE',
        data: ids,
    })
}

/**
 * 更改用户状态
 * @param {*} id
 */
export function changeUserStatusApi(id) {
    return request({
        url: `${base_url}/status/${id}`,
        method: 'PATCH',
    })
}

/**
 * 更改用户角色
 * @param {*} id
 */
export function changeUserRoleApi(id, role) {
    return request({
        url: `${base_url}/role/${id}`,
        method: 'PATCH',
        params: {
            role
        }
    })
}

/**
 * 用户更改密码
 * @param {*} oPassword 
 * @param {*} nPassword 
 */
export function changeUserPasswrodApi(oPassword, nPassword) {
    return request({
        url: base_url + '/password',
        method: 'PATCH',
        params: {
            oPassword,
            nPassword
        }
    })
}

/**
 * 用户更新信息
 * @param {*} user 
 */
export function updateUserApi(user) {
    return request({
        url: base_url,
        method: 'PUT',
        data: user
    })
}